package com.study.kt.project.game_tank.model

import com.study.kt._04project.game_tank.Config
import com.study.kt._04project.game_tank.business.Attachable
import com.study.kt._04project.game_tank.business.Blockable
import com.study.kt._04project.game_tank.business.Destoryable
import com.study.kt._04project.game_tank.business.Sufferable
import com.study.kt._04project.game_tank.model.Blast
import com.study.kt._04project.game_tank.model.View
import org.itheima.kotlin.game.core.Composer
import org.itheima.kotlin.game.core.Painter

/**
 * 砖墙
 * 有阻挡、被攻击、消失的能力
 */
class Wall(override val x: Int, override val y: Int) : Blockable, Sufferable, Destoryable {

    //墙默认有3滴血
    override var blood: Int = 3

    /*
     初始参数可以通过构造方法传入
     override val x: Int = 100
     override val y: Int = 100*/
    override val width: Int = Config.block
    override val height: Int = Config.block

    override fun draw() {
        Painter.drawImage("img/wall.gif", x, y)
    }

    override fun notifySuffer(attachable: Attachable): Array<View>? {
        //被攻击了要减少血量
        blood -= attachable.attachPower
        //播放音乐
        Composer.play("snd/hit.wav")

        return arrayOf(Blast(x, y))
    }

    override fun isDestory(): Boolean {
        return blood <= 0
    }

}